home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / PCM / PLAYFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-26  |  22.1 KB  |  1,107 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   26 Feb 1993 11:24:08  $*/
  3. /*$Header:   X:/sccs/pcmapps/playfile.c_v   1.14   26 Feb 1993 11:24:08   DCODY  $*/
  4. /*$Log:   X:/sccs/pcmapps/playfile.c_v  $
  5.  * 
  6.  *    Rev 1.14   26 Feb 1993 11:24:08   DCODY
  7.  * No change.
  8.  * 
  9.  *    Rev 1.13   26 Feb 1993 10:18:20   DCODY
  10.  * .VOC interim buffer is now allocated at runtime to match the DMA
  11.  * buffer division size.
  12.  * 
  13.  *    Rev 1.12   26 Jan 1993 16:13:22   BCRANE
  14.  * oops, quoted the TEXT_MSG48 equate!
  15.  * 
  16.  *    Rev 1.11   26 Jan 1993 15:57:48   BCRANE
  17.  * added check for format type
  18.  * 
  19.  *    Rev 1.10   06 Oct 1992 15:15:50   DCODY
  20.  * No change.
  21.  * 
  22.  *    Rev 1.9   24 Sep 1992 08:59:20   DCODY
  23.  * changed MVGetHardware to mvGetHardware
  24.  * 
  25.  *    Rev 1.8   14 Sep 1992 17:22:38   SHAO_M
  26.  * Put all the text strings used in printf into playtext.h
  27.  * 
  28.  *    Rev 1.0   14 Sep 1992 17:01:30   unknown
  29.  * Initial revision.
  30.  * 
  31.  *    Rev 1.7   13 Aug 1992 08:26:18   DCODY
  32.  * corrected #if/#endif and } placement for TB stuff...
  33.  * 
  34.  *    Rev 1.6   04 Aug 1992 11:39:54   DCODY
  35.  * corrected t&l spelling
  36.  * 
  37.  *    Rev 1.5   28 Jul 1992 14:29:06   DCODY
  38.  * updated for Thunderboard and Thunder&Lightning
  39.  * 
  40.  *    Rev 1.4   20 Jul 1992 11:39:02   DCODY
  41.  * call to mvGetHWVersion now uses active I/O address detection.
  42.  * 
  43.  *    Rev 1.3   13 Jul 1992 18:54:14   DCODY
  44.  * removed initmvsound call
  45.  * 
  46.  *    Rev 1.2   01 Jul 1992 11:55:16   DCODY
  47.  * GaryL: Added OEM compiler flag checking for Welcome()
  48.  * to use the generic board name and to not display the MVI copyright.
  49.  * Note that the copyright is still present, as an imbedded static string.
  50.  * 
  51.  *    Rev 1.1   23 Jun 1992 16:09:50   DCODY
  52.  * pas2 update...
  53.  * 
  54.  *    Rev 1.0   15 Jun 1992 09:26:40   BCRANE
  55.  * Initial revision.
  56. */
  57. /*$Logfile:   X:/sccs/pcmapps/playfile.c_v  $*/
  58. /*$Modtimes$*/
  59. /*$Revision:   1.14  $*/
  60. /*$Workfile:   playfile.c  $*/
  61.  
  62.  
  63.     /*\
  64.     |*|----====< PLAYFILE.C >====----
  65.     |*|
  66.     |*| Play the voice file from disk to the PCM hardware
  67.     |*|
  68.     |*| Copyright (c) 1991, Media Vision, Inc. All rights reserved.
  69.     |*|
  70.     \*/
  71.  
  72. #ifndef OEM
  73. #define OEM    0    /* OEM compile flag                    */
  74. #endif
  75. #ifndef PROAS
  76. #define PROAS    0    /* Pro Audio Spectrum compile flag                    */
  77. #endif
  78. #ifndef THUNDER
  79. #define THUNDER 0    /* Thunder Board compile flag                        */
  80. #endif
  81.  
  82. #include <stdio.h>
  83. #include <stdlib.h>
  84. #include <malloc.h>
  85. #include <signal.h>
  86. #include "playtext.h"
  87.  
  88. #if PROAS
  89. #include "play.h"
  90. #include "common.h"
  91. #include "pcmio.h"
  92. #endif
  93.  
  94. #if THUNDER
  95. #include "proto.h"
  96. #include "play.h"
  97. #include "common.h"
  98. #include "pcmio.h"
  99. #include "mvsound.h"
  100. #endif
  101.  
  102.  
  103.     /*\
  104.     |*|----====< Global Variables >====----
  105.     \*/
  106.  
  107.         extern int DMARunning;
  108.  
  109.         long mvGetHWVersion (int);
  110.  
  111.  
  112.     /*\
  113.     |*|----====< Local Variables >====----
  114.     \*/
  115.  
  116.         static FILE *inf;                /* user input file                */
  117.  
  118.         static long SampleRate = 11025L;/* default sample rate            */
  119.         static int    StereoMono = 0;     /* default to mono                */
  120.         static int    Filter       = -1;    /* filter override #            */
  121.         static int    Compression= FALSE; /* compressed data                */
  122.  
  123.         static int    DMAChannel = -1;    /* default to standard DMA        */
  124.         static int    IRQChannel = -1;    /* default to standard IRQ        */
  125.  
  126.         static int    speed = 100;        /* 100 percent                    */
  127.  
  128.         static int    UserStereoMono = -1;/* user's override flag = mono  */
  129.         static long UserSampleRate = -1;/* user's override = 11k        */
  130.         static long DataLength       = -1;/* -1 goes to EOF                */
  131.  
  132.         static int    maxsize    =16;     /* 16k DMA buffer size            */
  133.         static int    maxdiv       = 4;     /* 4k divisions on the DMA        */
  134.         static int    datasize   = 8;     /* 8 bit or 16 bit pcm            */
  135.         static int    dsoverride = FALSE; /* data size override            */
  136.  
  137. #define ALLOTHERS    0                    /* assume an 8 bit data file    */
  138. #define WAVEFILE    1                    /* wave type of file            */
  139. #define VOCFILE     2                    /* .voc 8 bit pcm file            */
  140.         static int    FileType;            /* type of source file            */
  141.  
  142.         int    VocBuffLen = 4096;
  143.         static char *vocbuffer;         /* interrim .VOC data block     */
  144.  
  145.         static long VOCBlockLength;     /* current block length         */
  146.         static char VOCBlockType;        /* current block type            */
  147.         static char VOCPackType;
  148.  
  149.         int  CommandLine    ( int, char *[] );
  150.         int  DoExit         ( int );
  151.         int  FetchVOCData   ( char * ); /* buffer of PCM data           */
  152.         int  PreProcessFile ( char * );
  153.         int  SetupPlayRate  ( );
  154.         void SetupSound     ( );
  155.  
  156.  
  157.     /*\
  158.     |*|----====< Main >====----
  159.     |*|
  160.     |*| Play the voice file out to the PCM hardware
  161.     |*|
  162.     \*/
  163.  
  164. main(argc,argv)
  165.     int  argc;
  166.     char *argv[];
  167. {
  168. char c;
  169.  
  170.     /* give the opening welcome & checkout the hardware                 */
  171.  
  172.         Welcome();
  173.  
  174.     /* set the runtime switches                                         */
  175.  
  176.         CommandLine (argc,argv);
  177.  
  178.     /* disable the ^C                                                   */
  179.  
  180.         signal (SIGINT,SIG_IGN);
  181.  
  182.     /* need a file name to play, exit if not found                        */
  183.  
  184.         PreProcessFile (argv[1]);
  185.  
  186.         if (OpenPCMBuffering(DMAChannel,IRQChannel,maxsize,maxdiv)) {
  187.             printf (TXT_MSG1);
  188.             DoExit (-1);
  189.         }
  190.  
  191.     /* setup how this file sounds                                        */
  192.  
  193.         SetupSound();
  194.  
  195.     /* Start the DMA & wait till an ESC is typed or data ends           */
  196.  
  197.         printf (TXT_MSG2);
  198.  
  199.         if (FileType <= WAVEFILE) {
  200.  
  201.             /* .WAV & all other files can go out using normal file I/O    */
  202.  
  203.             if (StartFileOutput( inf, DataLength )) {
  204.  
  205.                 while (1) {
  206.  
  207.                     /* if all done, then just break                     */
  208.  
  209.                         if (!ContinueFileOutput())
  210.                             break;
  211.  
  212.                     /* if ESC typed, kill the DMA & exit                */
  213.  
  214.                         if (kbhit()) {
  215.  
  216.                             if ((c = getch()) == 0x1b) {
  217.                                 StopDMAIO();
  218.                                 break;
  219.                             }
  220.                             if (c == ' ') {
  221.                                 PausePCM();
  222.                                 printf (TXT_MSG3);
  223.                                 GetKey();
  224.                                 printf (TXT_MSG4);
  225.                                 ResumePCM();
  226.                             }
  227.                         }
  228.                 }
  229.             }
  230.         }
  231.         else {
  232.  
  233.             /* if there is data available, play it...                    */
  234.  
  235.             if (FetchVOCData(vocbuffer)) {
  236.  
  237.                 /* start the output with the first block of data        */
  238.  
  239.                 if (StartBlockOutput( vocbuffer )) {
  240.  
  241.                     /* fetch the next block of data                     */
  242.  
  243.                     FetchVOCData(vocbuffer);
  244.  
  245.                     while (1) {
  246.  
  247.                         /* if the block can be passed, reload it        */
  248.  
  249.                             if (ContinueBlockOutput(vocbuffer)) {
  250.                                 if (!FetchVOCData(vocbuffer))
  251.                                     break;
  252.                             }
  253.  
  254.                         /* if ESC typed, kill the DMA & exit            */
  255.  
  256.                             if (kbhit()) {
  257.  
  258.                                 if ((c = getch()) == 0x1b) {
  259.                                     StopDMAIO();
  260.                                     DoExit(0);
  261.                                 }
  262.                                 if (c == ' ') {
  263.                                     PausePCM();
  264.                                     printf (TXT_MSG5);
  265.                                     GetKey();
  266.                                     printf (TXT_MSG6);
  267.                                     ResumePCM();
  268.                                 }
  269.                             }
  270.                     }
  271.  
  272.                     /* wait till the DMA finishes                        */
  273.  
  274.                     while (DMARunning) ;
  275.  
  276.                 }
  277.             }
  278.         }
  279.  
  280.     /* exit to DOS                                                        */
  281.  
  282.         DoExit(0);
  283.  
  284. }
  285.  
  286.  
  287.     /*\
  288.     |*|----====< CommandLine >====----
  289.     |*|
  290.     |*| process the command line switches
  291.     |*|
  292.     \*/
  293. int CommandLine(argc,argv)
  294.     int argc;
  295.     char *argv[];
  296. {
  297. char *s;
  298. int n,temp;
  299. long longtemp;
  300.  
  301.     /* exit if no additional parameters                                 */
  302.  
  303.         if (argc < 2) {
  304.             GiveHelps();
  305.             DoExit (-1);
  306.         }
  307.  
  308.         n = 2;
  309.         while (n < argc) {
  310.  
  311.             s = argv[n++];
  312.  
  313.             if (*s == '/') s++;
  314.             if (*s == '-') s++;
  315.  
  316.             switch (*s & 0x5f) {
  317.  
  318. #if PROAS
  319.                 case '1' & 0x5f:
  320.                 case '8' & 0x5f:
  321.                     if (*++s == '6')
  322.                         datasize   = 16;
  323.                     dsoverride = TRUE;
  324.  
  325.                     break;
  326.  
  327.                 case 'F':
  328.                     Filter = *++s - 0x30;
  329.                     if ((Filter > 6) || (Filter < 0))
  330.                         Filter = -1;
  331.                     break;
  332. #endif
  333.  
  334.                 case 'D':
  335.                     temp = *++s - 0x30;
  336.                     if ((temp <= 7) && (temp >= 1)) {
  337.                         if (temp == 4) temp = 0;
  338.                         DMAChannel = temp;
  339.                     }
  340.                     break;
  341.  
  342.                 case 'I':
  343.                     if (sscanf (++s,"%d",&temp) == 1) {
  344.                         if ((1 << temp) & 0x9CBC)
  345.                             IRQChannel = temp;
  346.                     }
  347.                     break;
  348.  
  349.                 case 'M':
  350.                     maxsize = 64;
  351.                     maxdiv    = 16;
  352.                     break;
  353.  
  354.                 case 'R':
  355.                     if (sscanf (++s,"%ld",&longtemp) == 1) {
  356.                         if ((longtemp >4000L) && (longtemp < 88200L))
  357.                             UserSampleRate = longtemp;
  358.                     }
  359.                     break;
  360.  
  361.                 case 'S':
  362.                     s++;
  363.  
  364.                     if (*s == '\0')
  365.                         UserStereoMono = 1;
  366.                     else {
  367.                         if (sscanf (s,"%d",&temp) == 1) {
  368.                             if ((temp >= 0) && ( temp <= 200))
  369.                                 speed = temp;
  370.                         }
  371.                     }
  372.                     break;
  373.  
  374.                 default:
  375.                     break;
  376.             }
  377.         }
  378. }
  379.  
  380.  
  381.     /*\
  382.     |*|----====< DoExit() >====----
  383.     |*|
  384.     |*| Exit to DOS
  385.     |*|
  386.     \*/
  387. int DoExit(cc)
  388.     int cc;
  389. {
  390.         ClosePCMBuffering();
  391.         exit (cc);
  392. }
  393.  
  394.  
  395.     /*\
  396.     |*|----====< GiveHelps() >====----
  397.     |*|
  398.     |*| print text helps & return
  399.     |*|
  400.     \*/
  401. int GiveHelps()
  402. {
  403.  
  404.     /* print & return...                                                */
  405.  
  406. #if PROAS
  407.         printf (TXT_MSG7);
  408.         printf (TXT_MSG8);
  409.         printf (TXT_MSG9);
  410.         printf (TXT_MSG10);
  411.         printf (TXT_MSG11);
  412.         printf (TXT_MSG12);
  413.         printf (TXT_MSG13);
  414.         printf (TXT_MSG14);
  415.         printf (TXT_MSG15);
  416.         printf (TXT_MSG16);
  417.         printf (TXT_MSG17);
  418. #endif
  419.  
  420. #if THUNDER
  421.         printf (TXT_MSG18);
  422.         printf (TXT_MSG19);
  423.         printf (TXT_MSG20);
  424.  #if THUNDER==2
  425.         printf (TXT_MSG21);
  426.         printf (TXT_MSG22);
  427.  #else
  428.         printf (TXT_MSG23);
  429.  #endif
  430.         printf (TXT_MSG24);
  431.         printf (TXT_MSG25);
  432.         printf (TXT_MSG26);
  433. #endif
  434. }
  435.  
  436.  
  437.     /*\
  438.     |*|----====< FetchVOCData >====----
  439.     |*|
  440.     |*| Get a new key
  441.     |*|
  442.     \*/
  443. int FetchVOCData(buff)
  444.     char *buff;
  445. {
  446. int loaded = 0, n;
  447. int looping = TRUE;
  448. int remaining = VocBuffLen;
  449.  
  450.     /* grab the next block of data                                        */
  451.  
  452.         looping = 1;
  453.         while (looping) {
  454.  
  455.             /* process the header                                        */
  456.  
  457.                 switch (VOCBlockType) {
  458.  
  459.                     case TERMINATOR:
  460.  
  461.                         for (;remaining;remaining--)
  462.                             *buff++ = 0x80;
  463.                         remaining = 0;
  464.                         looping = 0;        /* this will knock us out    */
  465.                         break;
  466.  
  467.                     case VOICECONTINUE:
  468.                     case VOICEDATA:
  469.  
  470.                         /* load the data, try to span blocks            */
  471.  
  472.                         if (VOCBlockLength < remaining) {
  473.                             remaining -= VOCBlockLength;
  474.                             n = fread (buff,1,(size_t)VOCBlockLength,inf);
  475.                             loaded += n;
  476.                             buff += n;
  477.                             VOCBlockLength = 0;
  478.                         }
  479.                         else {
  480.                             n = fread(buff,1,remaining,inf);
  481.                             loaded += n;
  482.                             VOCBlockLength -= n;
  483.                             looping = remaining = 0;
  484.                         }
  485.                         break;
  486.  
  487.                     case SILENCE:
  488.  
  489.                         /* load the data, try to span blocks            */
  490.  
  491.                         if (VOCBlockLength < remaining) {
  492.                             remaining -= VOCBlockLength;
  493.                             loaded += VOCBlockLength;
  494.                             for (;VOCBlockLength;VOCBlockLength--)
  495.                                 *buff++ = 0x80;
  496.                         }
  497.                         else {
  498.                             loaded = remaining;
  499.                             VOCBlockLength -= remaining;
  500.                             for (;remaining;remaining--)
  501.                                 *buff++ = 0x80;
  502.                             looping = remaining = 0;
  503.                         }
  504.                         break;
  505.  
  506.                     case MARKER:
  507.                     case REPEAT:
  508.                     case ENDREPEAT:
  509.                     case ASCIITEXT:
  510.  
  511.                         /* all the rest of the header were eaten by the     */
  512.                         /* "GetNextBlock" routine. We will continue till we */
  513.                         /* find data, or the terminating record             */
  514.  
  515.                     default:
  516.                         break;
  517.                 }
  518.  
  519.                 /* span blocks, but exit on EOF                             */
  520.  
  521.                 if (remaining) {
  522.                     if (!GetNextBlock()) {
  523.                         for (;remaining;remaining--)
  524.                             *buff++ = 0x80;
  525.                         looping = FALSE;
  526.                     }
  527.                 }
  528.         }
  529.  
  530.     /* return with data data block                                            */
  531.  
  532.         return(loaded);
  533. }
  534.  
  535.  
  536.     /*\
  537.     |*|----====< GetKey() >====----
  538.     |*|
  539.     |*| Get a new key
  540.     |*|
  541.     \*/
  542. int GetKey()
  543. {
  544. char c;
  545.  
  546.     while (kbhit()) getch();
  547.  
  548.     while (!kbhit()) ;
  549.     if (getch() == 0) getch();
  550.  
  551. }
  552.  
  553.  
  554.     /*\
  555.     |*|----====< GetNextBlock() >====----
  556.     |*|
  557.     |*| Process the header to the next block, & return TRUE if data is
  558.     |*| pointed to.
  559.     |*|
  560.     \*/
  561. int GetNextBlock()
  562. {
  563. int looping = TRUE;
  564. long l;
  565.  
  566.     /* get the record type & process to get the sample rate             */
  567.  
  568.         VOCBlockLength = 0;             /* we must end up with data!    */
  569.         while (looping) {
  570.  
  571.             switch (VOCBlockType = fgetc(inf)) {
  572.  
  573.                 case TERMINATOR:
  574.                     return(0);            /* if at the end, just exit     */
  575.  
  576.                 case SILENCE:
  577.                     fgetc(inf);fgetc(inf);fgetc(inf);
  578.                     VOCBlockLength  = fgetc(inf) & 0xff;
  579.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  580.                     SetupPlayRate(fgetc(inf) & 0xff);
  581.                     VOCBlockLength -= 3;    /* 3 less for header data    */
  582.                     looping = FALSE;
  583.                     break;
  584.  
  585.                 case VOICEDATA:
  586.                     VOCBlockLength    = fgetc(inf) & 0xff;
  587.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 8;
  588.                     VOCBlockLength += ((long)(fgetc(inf) & 0xff)) << 16;
  589.                     SetupPlayRate(fgetc(inf) & 0xff);
  590.  
  591.                     /* determine mono/stereo                            */
  592.  
  593.                     StereoMono = 0;
  594.                     if (((VOCPackType = fgetc(inf)) & 0xff) == 5) {
  595.                         StereoMono = 1;
  596.                         VOCPackType = 0;
  597.                     }
  598. #if THUNDER
  599.                     /* determine compression                            */
  600.  
  601.                     if (VOCPackType <= 3)    /* types 0 - 3                */
  602.                         Compression = VOCPackType;
  603. #endif
  604.                     VOCBlockLength -= 2;    /* 2 less for header data   */
  605.                     looping = FALSE;
  606.                     break;
  607.  
  608.                 case ASCIITEXT:
  609.                     l  = fgetc(inf) & 0xff;
  610.                     l += ((long)(fgetc(inf) & 0xff)) << 8;
  611.                     l += ((long)(fgetc(inf) & 0xff)) << 16;
  612.                     for (;l;l--)
  613.                         fgetc(inf);
  614.                     break;
  615.  
  616.                 case MARKER:
  617.                 case REPEAT:
  618.                     fgetc(inf);fgetc(inf);
  619.                 case ENDREPEAT:
  620.                     fgetc(inf);fgetc(inf);fgetc(inf);
  621.                     break;
  622.  
  623.                 default:
  624.                     printf (TXT_MSG27);
  625.                     DoExit(-1);
  626.                     break;
  627.  
  628.             }
  629.         }
  630.  
  631.     /* we leave the file pointing to the first data byte                */
  632.  
  633.         return(1);
  634. }
  635.  
  636.     /*\
  637.     |*|----====< PreProcessFile >====----
  638.     |*|
  639.     |*| Fill the play buffer with the contents of the disk file
  640.     |*|
  641.     \*/
  642. int PreProcessFile (fn)
  643.     char *fn;
  644. {
  645. char buff[100];
  646. int n,looping;
  647. long psize,l;
  648. char *p,*b;
  649. long* ptr;
  650. FILE *wf;
  651.  
  652.     /* attempt to open the users disk file                                */
  653.  
  654.         if ((inf = fopen(fn,"rb")) == 0) {
  655.  
  656.             strcpy (buff,fn);
  657.             strcat (buff,".WAV");
  658.             if ((inf = fopen(buff,"rb")) == 0) {
  659.  
  660.                 strcpy (buff,fn);
  661.                 strcat (buff,".VOC");
  662.                 if ((inf = fopen(buff,"rb")) == 0) {
  663.  
  664.                     printf (TXT_MSG28,fn);
  665.                     DoExit (-1);
  666.                 }
  667.             }
  668.         }
  669.  
  670.     /* get the 1st 2 characters in the file                             */
  671.  
  672.         n = fgetc(inf) & 0xff;
  673.         n = n + ((fgetc(inf) & 0xff) << 8);
  674.  
  675.         fseek (inf,0L,SEEK_SET); /* rewind to the start                 */
  676.  
  677.     /* special case a .WAV file                                         */
  678.  
  679.         if (n == 0x4952) {
  680.              ProcessWAVFile();
  681.              return(0);
  682.         }
  683.  
  684.     /* special case anything else than a .VOC file                        */
  685.  
  686.         if (n != 0x7243) {        /* if NE to Creative..., then it's PCM  */
  687.              ProcessPCMFile();
  688.              return(0);
  689.         }
  690.  
  691.     /* .VOC type of source file                                         */
  692.  
  693.         FileType = VOCFILE;
  694.  
  695.     /* allocate the memory required for the interim block                */
  696.  
  697.         VocBuffLen = (int) ( (((long)maxsize) * 1024L / maxdiv) &0xffff );
  698.  
  699.         if ((vocbuffer = malloc( VocBuffLen)) == 0) {
  700.             printf ("Cannot allocate the .VOC buffer!\n");
  701.             DoExit(-1);
  702.         }
  703.  
  704.     /* get the header of the voice file                                 */
  705.  
  706.         b = &buff[0];
  707.         fseek(inf,0L,SEEK_SET);         /* move to the first byte        */
  708.         for (n=0;n<(sizeof (VOCHDR));n++)
  709.             *b++ = fgetc(inf);
  710.  
  711.         if (feof(inf)) {
  712.             printf (TXT_MSG29);
  713.             DoExit (-1);
  714.         }
  715.  
  716.     /* Make sure it's a legit file                                      */
  717.  
  718.         if (strncmp (buff,"Creative Voice File",0x13) != 0) {
  719.             printf (TXT_MSG30);
  720.             DoExit (-1);
  721.         }
  722.  
  723.         p = &buff[0x14];                /* get a pointer to the offset    */
  724.  
  725.         psize = LONG(*p) & 0xffff;        /* get the 16 bit word            */
  726.  
  727.         fseek(inf,psize,SEEK_SET);        /* move to the first byte        */
  728.  
  729.         if (!GetNextBlock())            /* process the next header        */
  730.             DoExit(0);
  731.  
  732. }
  733.  
  734.  
  735.     /*\
  736.     |*|----====< ProcessWAVFile >====----
  737.     |*|
  738.     |*| load the header from our WAV file format
  739.     |*|
  740.     \*/
  741. int ProcessWAVFile(f)
  742. {
  743. int n;
  744. char *b,c;
  745. WaveInfo whd;
  746. DataHeader dhd;
  747.  
  748.     /* We are a WAVE file                                                */
  749.  
  750.         FileType = WAVEFILE;            /* type of source file          */
  751.  
  752.     /* eat the RIFF portion of the header                                */
  753.  
  754.         c = fgetc(inf);
  755.  
  756.         if (c == 'R') {
  757.             for (n=7;n;n--)
  758.                 fgetc(inf);
  759.             c = fgetc(inf);
  760.         }
  761.  
  762.     /* pas up the wave block header name                                */
  763.  
  764.         if (c != 'W') {
  765.             printf (TXT_MSG31);
  766.             DoExit(-1);
  767.         }
  768.         fgetc(inf); fgetc(inf); fgetc(inf);     /* move past the data    */
  769.  
  770.     /* pass up the format section name                                    */
  771.  
  772.         c = fgetc(inf);
  773.         if (c != 'f') {
  774.             printf (TXT_MSG32);
  775.             DoExit(-1);
  776.         }
  777.         for (n=7;n;n--)
  778.             fgetc(inf);                         /* move past the data    */
  779.  
  780.     /* load the actual header data                                        */
  781.  
  782.         b = (char *) &whd;
  783.         for (n=0;n<sizeof (WaveInfo);n++)
  784.             *b++ = fgetc(inf);
  785.  
  786.             {
  787.             if (whd.formatTag != 1)
  788.                 {
  789.                 printf(TXT_MSG48);
  790.                 DoExit(-1);
  791.                 }
  792.             }
  793.  
  794.     /* grab the sample rate                                             */
  795.  
  796.         StereoMono = whd.nChannels - 1;
  797.         SampleRate = whd.nSamplesPerSec;
  798.  
  799.     /* setup the data size only if no override has been requested        */
  800.  
  801.         if (!dsoverride)
  802.             datasize   = whd.nBitsPerSample;
  803.  
  804.     /* go to the data section and get the data length                    */
  805.  
  806.         b = (char *) &dhd;
  807.         for (n=0;n<sizeof(DataHeader);n++)
  808.             *b++ = fgetc(inf);                    /* move past the data    */
  809.  
  810.         if (dhd.name[0] != 'd') {
  811.             printf (TXT_MSG33);
  812.             DoExit(-1);
  813.         }
  814.  
  815.         DataLength = dhd.length;
  816.  
  817. }
  818.  
  819.  
  820.     /*\
  821.     |*|----====< ProcessPCMFile >====----
  822.     |*|
  823.     |*| load the header from our PCM file format
  824.     |*|
  825.     \*/
  826. int ProcessPCMFile()
  827. {
  828. int n;
  829. char *b;
  830.  
  831.     /* we are some unknown data type                                    */
  832.  
  833.         FileType = ALLOTHERS;            /* type of source file            */
  834.  
  835.     /* ask for the sample rate                                          */
  836.  
  837.         if (UserSampleRate != -1) {
  838.             SampleRate = UserSampleRate;
  839.  
  840.             if (UserStereoMono == -1)
  841.                 UserStereoMono = 0;
  842.  
  843.             StereoMono = UserStereoMono;
  844.         }
  845.         else {
  846.  
  847.             SampleRate = 11025L;
  848.             printf (TXT_MSG34);
  849.             while (1) {
  850.                 if (scanf ("%ld",&SampleRate) == 1)
  851.                     break;
  852.             }
  853.  
  854.             printf (TXT_MSG35);
  855.             while (1) {
  856.                 if (scanf ("%d",&StereoMono) == 1) {
  857.                     StereoMono--;    /* make it zero based                */
  858.                     break;
  859.                 }
  860.             }
  861.         }
  862.  
  863.         if ((StereoMono < 0) || (StereoMono > 1))
  864.             StereoMono = 0;
  865. }
  866.  
  867.  
  868.     /*\
  869.     |*|----====< SetupPlayRate >====----
  870.     |*|
  871.     |*| Setup the playing rate of the interrupt routine.
  872.     |*|
  873.     \*/
  874. int SetupPlayRate(n)
  875.     int n;
  876. {
  877.  
  878.     /* we will use a default rate                                        */
  879.  
  880.         SampleRate = 11025L;
  881.  
  882.     /* search for the real rate                                         */
  883.  
  884.         while (1) {
  885.  
  886.             if (n <= 6) {
  887.                 SampleRate = 4000L;         /* 4000 kh sampling         */
  888.                 break;
  889.             }
  890.  
  891.             if (n <= 56) {
  892.                 SampleRate = 5000L;         /* 5000 kh sampling         */
  893.                 break;
  894.             }
  895.  
  896.             if (n <= 90) {
  897.                 SampleRate = 6000L;         /* 6000 kh sampling         */
  898.                 break;
  899.             }
  900.  
  901.             if (n <= 114) {
  902.                 SampleRate = 7000L;         /* 7000 kh sampling         */
  903.                 break;
  904.             }
  905.  
  906.             if (n <= 131) {
  907.                 SampleRate = 8000L;         /* 8000 kh sampling         */
  908.                 break;
  909.             }
  910.  
  911.             if (n <= 145) {
  912.                 SampleRate = 9000L;         /* 9000 kh sampling         */
  913.                 break;
  914.             }
  915.  
  916.             if (n <= 156) {
  917.                 SampleRate = 10000L;        /* 10000 kh sampling        */
  918.                 break;
  919.             }
  920.  
  921.             if (n <= 166) {
  922.                 SampleRate = 11000L;        /* 11000 kh sampling        */
  923.                 break;
  924.             }
  925.  
  926.             if (n <= 173) {
  927.                 SampleRate = 12000L;        /* 11000 kh sampling        */
  928.                 break;
  929.             }
  930.  
  931.             if (n <= 180) {
  932.                 SampleRate = 13000L;        /* 11000 kh sampling        */
  933.                 break;
  934.             }
  935.  
  936.             if (n <= 185) {
  937.                 SampleRate = 14000L;        /* 11000 kh sampling        */
  938.                 break;
  939.             }
  940.  
  941.             if (n <= 190) {
  942.                 SampleRate = 15000L;        /* 11000 kh sampling        */
  943.                 break;
  944.             }
  945.  
  946.             if (n <= 194) {
  947.                 SampleRate = 16000L;        /* 11000 kh sampling        */
  948.                 break;
  949.             }
  950.  
  951.             if (n <= 198) {
  952.                 SampleRate = 17000L;        /* 11000 kh sampling        */
  953.                 break;
  954.             }
  955.  
  956.             if (n <= 201) {
  957.                 SampleRate = 18000L;        /* 11000 kh sampling        */
  958.                 break;
  959.             }
  960.  
  961.             if (n <= 204) {
  962.                 SampleRate = 19000L;        /* 11000 kh sampling        */
  963.                 break;
  964.             }
  965.  
  966.             if (n <= 206) {
  967.                 SampleRate = 20000L;        /* 11000 kh sampling        */
  968.                 break;
  969.             }
  970.  
  971.             if (n <= 209) {
  972.                 SampleRate = 21000L;        /* 11000 kh sampling        */
  973.                 break;
  974.             }
  975.  
  976.             if (n <= 211) {
  977.                 SampleRate = 22000L;        /* 11000 kh sampling        */
  978.                 break;
  979.             }
  980.  
  981.             if (n <= 215) {
  982.                 SampleRate = 23000L;        /* 11000 kh sampling        */
  983.                 break;
  984.             }
  985.  
  986.             /* if unknown value, bomb out...                            */
  987.  
  988.                 printf (TXT_MSG36);
  989.                 DoExit(0);
  990.  
  991.         }
  992. }
  993.  
  994.  
  995.     /*\
  996.     |*|----====< SetupSound() >====----
  997.     |*|
  998.     |*| Setup the sample rate, stereo/mono.
  999.     |*|
  1000.     \*/
  1001. void SetupSound()
  1002. {
  1003.  
  1004.     /* if the user wants it different...                                */
  1005.  
  1006.         if (UserSampleRate != -1)
  1007.             SampleRate = UserSampleRate;
  1008.  
  1009.         if (UserStereoMono != -1)
  1010.             StereoMono = UserStereoMono;
  1011.  
  1012.     /* speed is the user's %. from 0 to 200 %                           */
  1013.  
  1014.         SampleRate = ((SampleRate * speed) + 50) / 100;
  1015.  
  1016. #if PROAS
  1017.         ChooseFilter( SampleRate, Filter );
  1018. #endif
  1019.  
  1020.         PCMState (SampleRate, StereoMono, Compression, datasize );
  1021. }
  1022.  
  1023.  
  1024.     /*\
  1025.     |*|----====< Welcome >====----
  1026.     |*|
  1027.     |*| Print the logo & check for the appropriate hardware
  1028.     |*|
  1029.     \*/
  1030. Welcome()
  1031. {
  1032. long ver;
  1033.  
  1034.     /* give the normal stuff...                                         */
  1035.  
  1036. #if OEM
  1037.  
  1038.  #if PROAS
  1039.         printf (TXT_MSG37);
  1040.  #endif
  1041.  
  1042.  #if THUNDER
  1043.         printf (TXT_MSG38);
  1044.  #endif
  1045.  
  1046.         {
  1047.                 static char    zsCopyright[] = "Copyright (c) 1991,1992 Media Vision, Inc. All Rights Reserved\n\n";
  1048.         }
  1049.  
  1050. #else
  1051.  
  1052.  #if PROAS
  1053.         printf (TXT_MSG39);
  1054.  #endif
  1055.  
  1056.  #if THUNDER
  1057.   #if THUNDER==2
  1058.         printf (TXT_MSG40);
  1059.   #else
  1060.         printf (TXT_MSG41);
  1061.   #endif
  1062.  #endif
  1063.  
  1064.         printf (TXT_MSG42);
  1065.  
  1066. #endif  //OEM
  1067.  
  1068.     /* check for the hardware                                            */
  1069.  
  1070. #if PROAS
  1071.         ver = mvGetHWVersion(USE_ACTIVE_ADDR); /* get the version               */
  1072.         if (ver == -1) {
  1073.  #if OEM
  1074.             printf (TXT_MSG43);
  1075.  #else     //OEM
  1076.             printf (TXT_MSG44);
  1077.  #endif  //OEM
  1078.             GiveHelps();
  1079.             exit(-1);
  1080.         }
  1081. #endif
  1082.  
  1083. #if THUNDER
  1084.         ver = mvGetHWVersion(0);        /* get the version, or something.. */
  1085.         if ((ver < 0) || ((ver & 0xffff0000) != 0x00010000)) {
  1086.  #if OEM
  1087.             printf (TXT_MSG45);
  1088.  #else     //OEM
  1089.   #if THUNDER==2
  1090.             printf (TXT_MSG46);
  1091.   #else
  1092.             printf (TXT_MSG47);
  1093.   #endif
  1094.  #endif
  1095.             GiveHelps();
  1096.             exit(-1);
  1097.         }
  1098.  
  1099. #endif  //THUNDER
  1100. }
  1101.  
  1102.     /*\
  1103.     |*| end of PLAYFILE.C
  1104.     \*/
  1105.  
  1106.  
  1107.